package org.devlabs35.javamail;

import java.io.IOException;
import java.io.OutputStream;
import java.util.Properties;

import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Multipart;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

public class SendMail {

	public static void main(String[] args) {
		String html = "<!DOCTYPE html><html><body><pre>This ispreformatted text.It preserves      both spacesand line breaks.</pre><p>The pre tag is good for displaying computer code:</p><pre>for i = 1 to 10     print inext i</pre></body></html>";
		String user = "sairam";
		String password = "root";

		String fromAddress = "sairam@localhost";
		String toAddress = "sairam2@localhost";

		// Create a mail session
		Properties properties = new Properties();
		properties.put("mail.smtp.host", "localhost");
		properties.put("mail.smtp.port", "3525");
		properties.put("mail.smtp.username", user);
		properties.put("mail.smtp.password", password);
		Session session = Session.getDefaultInstance(properties, null);

		try {
			Message message = new MimeMessage(session);
			message.setFrom(new InternetAddress(fromAddress));
			message.setRecipients(Message.RecipientType.TO,
					InternetAddress.parse(toAddress));

			message.setSubject("Email from our JAMES Server");
			message.setText("Luke, I'm your father!!");
			message.setContent(html, "text/html");
			Multipart  multipart = new Multipart() {
				
				@Override
				public void writeTo(OutputStream os) throws IOException, MessagingException {
					
					
				}
			};
			//message.setContent(multipart);
			Transport.send(message);

			System.out.println("Email sent successfully");
		} catch (MessagingException e) {
			e.printStackTrace();
		}
	}
}